﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Appointments.Schedules;

namespace YaAppoint.Web.Controllers
{
    /// <summary>
    /// 排班计划控制器
    /// </summary>
    public class ScheduleController(IScheduleAppService scheduleAppService) : AbpController
    {
        private readonly IScheduleAppService _scheduleAppService = scheduleAppService;

        /// <summary>
        ///  获取科室设备类型下排班计划列表
        /// </summary>
        [HttpGet("/api/schedule/get-list")]
        public async Task<IActionResult> GetListAsync(Guid depId,Guid deviceTypeId,string? filterName)
        {
            return new JsonResult(await _scheduleAppService.GetListAsync(depId,deviceTypeId,filterName));
        }

        /// <summary>
        /// 保存新建
        /// </summary>
        [HttpPost("/api/schedule/submit-create")]
        public async Task<IActionResult> SubmitCreateAsync([FromBody] CreateScheduleDto dto, [FromQuery] Guid depId, [FromQuery] Guid deviceTypeId)
        {
            return new JsonResult(await _scheduleAppService.SubmitCreateAsync(dto,depId,deviceTypeId));
        }

        /// <summary>
        /// 保存编辑
        /// </summary>
        [HttpPost("/api/schedule/submit-edit")]
        public async Task<IActionResult> SubmitEditAsync([FromBody] ScheduleDto dto, [FromQuery] Guid depId, [FromQuery] Guid deviceTypeId)
        {
            return new JsonResult(await _scheduleAppService.SubmitEditAsync(dto,depId,deviceTypeId));
        }

        /// <summary>
        /// 加载详情
        /// </summary>
        [HttpGet("/api/schedule/get")]
        public async Task<IActionResult> GetAsync(Guid id)
        {
            return new JsonResult(await _scheduleAppService.GetAsync(id));
        }

        /// <summary>
        /// 启用/禁用
        /// </summary>
        [HttpGet("/api/schedule/toggle-disable")]
        public async Task<IActionResult> ToggleDisableAsync(Guid id)
        {
            return new JsonResult(await _scheduleAppService.ToggleDisableAsync(id));
        }

        /// <summary>
        /// 删除
        /// </summary>
        [HttpGet("/api/schedule/delete")]
        public async Task<IActionResult> Delete(Guid id)
        {
            return new JsonResult(await _scheduleAppService.Delete(id));
        }
    }
}
